package com.imooc.ecommerce.fallbackhandler;

import com.alibaba.fastjson.JSON;
import com.imooc.ecommerce.vo.JwtToken;
import com.imooc.ecommerce.vo.UsernameAndPassword;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>Sentinel 回退降级的兜底策略
 * <p>都需要是静态方法
 *
 * @author Yaxi.Zhang
 * @since 2022/11/20 16:35
 */
@Slf4j
public class QinyiFallbackHandler {
    /**
     * <h2>getTokenFromAuthorityService 方法的 fallback</h2>
     */
    public static JwtToken getTokenFromAuthorityServiceFallback(
            UsernameAndPassword usernameAndPassword
    ) {
        log.error("get token from authority service fallback: [{}]", JSON.toJSONString(usernameAndPassword));
        return new JwtToken("imooc-qinyi-fallback");
    }

    /**
     * <h2>ignoreException 方法的 fallback</h2>
     */
    public static JwtToken ignoreExceptionFallback(Integer code) {
        log.error("ignore exception input code: [{}] has trigger exception", code);
        return new JwtToken("imooc-qinyi-fallback");
    }
}
